function isValidEmailAddress(emailAddress) 
{
	var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
	return pattern.test(emailAddress);
}

function autoLoadDeposit()
{
	var type_tour = $("#type_tour").val();
	var mydeposit = '#deposit_name_' + type_tour;
	var deposit = $(mydeposit).val();
	//alert(deposit);		
	$("#deposit_tour").val(deposit);
	$("#book_deposit_tour").val(deposit);
}

function autoLoadPrice()
{
	//alert("sadf");
	var travel_in_party_of = $("#travel_in_party_of").val();	
	var mytravel = '#price_name_' + travel_in_party_of;
	var mytravelin = $(mytravel).val();
	var current_price = 0;
	if(mytravelin!="")
	{			
		var arr_mytravel = mytravelin.split("*|*");
		var type_tour = $("#type_tour").val();
		if(type_tour=="standard")
		{
			current_price = arr_mytravel[0];
		}
		else if(type_tour=="superior")
		{
			current_price = arr_mytravel[1];
		}
		else if(type_tour=="firstclass")
		{
			current_price = arr_mytravel[2];
		}
		else if(type_tour=="deluxe")
		{
			current_price = arr_mytravel[3];
		}			
	}	
	
	var type_tour = $("#type_tour").val();
	var mydeposit = '#deposit_name_' + type_tour;
	var deposit = $(mydeposit).val();
	deposit = (current_price/100)*deposit;
	//alert(deposit);		
	$("#deposit_tour").val(deposit);
	$("#book_deposit_tour").val(deposit);
	
	//alert(current_price);
	$("#hidden_tour_price").val(current_price);
	$("#show_tour_price").val(current_price);
}

$(document).ready(function(){		
	//**************************************************************************/
	$("#travel_in_party_of").change(function(){
	
		autoLoadPrice();
	});	
	//----------
	//autoLoadDeposit();
	autoLoadPrice();
	$("#type_tour").change(function(){
		
		//autoLoadDeposit();
		autoLoadPrice();
		
	});
	
	
	
	$("#submit_book_tour1").click(function(){
		
		var agent_name 		= $("#agent_name").val();
		var agent_email 	= $("#agent_email").val();
		var agent_address 	= $("#agent_address").val();
		var agent_phone 	= $("#agent_phone").val();		
		var agent_message 	= $("#agent_message").val();
		
		var tour_propose_day 	= $("#propose_day").val();
		var tour_propose_mo 	= $("#propose_mo").val();
		var tour_propose_ya 	= $("#propose_ya").val();
		var tour_captcha	 	= $("#captcha").val();
		var compare = "";
		
		var x=new Date();
		x.setFullYear(tour_propose_ya,tour_propose_mo,tour_propose_day);
		var today = new Date();
		
		
		if (x>=today)
		{
			compare = 'true';
			
		}
		
		var tamp = "";
		if(agent_name=="")
		{
			$("#contact_error_name").removeClass('contact_error');
			$("#contact_error_name").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_name").removeClass('contact_error_show');
			$("#contact_error_name").addClass('contact_error');
		}
		/*---------------------------------------------------------*/
		if(agent_email=="" || !isValidEmailAddress(agent_email))
		{
			$("#contact_error_email").removeClass('contact_error');
			$("#contact_error_email").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_email").removeClass('contact_error_show');
			$("#contact_error_email").addClass('contact_error');
		}
		/*---------------------------------------------------------*/
		if(agent_address=="")
		{
			$("#contact_error_address").removeClass('contact_error');
			$("#contact_error_address").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_address").removeClass('contact_error_show');
			$("#contact_error_address").addClass('contact_error');
		}
		/*---------------------------------------------------------*/
		if(agent_phone=="")
		{
			$("#contact_error_phone").removeClass('contact_error');
			$("#contact_error_phone").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_phone").removeClass('contact_error_show');
			$("#contact_error_phone").addClass('contact_error');
		}
		
		/*---------------------------------------------------------*/
		if(agent_message=="")
		{
			$("#contact_error_message").removeClass('contact_error');
			$("#contact_error_message").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_message").removeClass('contact_error_show');
			$("#contact_error_message").addClass('contact_error');
		}
		/*---------------------------------------------------------*/
		/* Company infomation */
		/*---------------------------------------------------------*/
		
		if(compare=="")
		{
			$("#contact_error_propose").removeClass('contact_error');
			$("#contact_error_propose").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_propose").removeClass('contact_error_show');
			$("#contact_error_propose").addClass('contact_error');
		}	
		
		if(tour_captcha=="")
		{
			$("#contact_error_captcha").removeClass('contact_error');
			$("#contact_error_captcha").addClass('contact_error_show');
			tamp += "ten";
		}
		else
		{
			$("#contact_error_captcha").removeClass('contact_error_show');
			$("#contact_error_captcha").addClass('contact_error');
		}
		/*---------------------------------------------------------*/
		
		
		if(tamp!="")
			return false;
		else return true;
		/*else
		{
			return true;
			
			var url =  $("#myprocess_url").val();	
			var show =  $("#myprocess_show_result").val();	
						
			var agentString = agent_name+'*|*'+agent_email+'*|*'+agent_address+'*|*'+agent_phone+'*|*'+agent_message;
			var companyString = company_name+'*|*'+company_email+'*|*'+company_address+'*|*'+company_phone+'*|*'+company_fax+'*|*'+company_message;
			url = url + "?action=travel-agent&agent="+agentString+'&company='+companyString;			
			dbagentsend(url,show);
			
		}*/		
	});	
});